package com.sushuo.base.bean.sql;


/**
 * Created by bolinlee on 2017/6/30
 * 排序
 */
public class Sort {
	private String column;//字段名
	private Direction direction;//排序方向
	public enum Direction{
		ASC,DESC;
	}

	public String getColumn() {
		return column;
	}

	public void setColumn(String column) {
		this.column = column;
	}

	public Direction getDirection() {
		return direction;
	}

	public void setDirection(Direction direction) {
		this.direction = direction;
	}

	public Sort(String column,Direction direction){
		this.column = column;
		this.direction = direction;
	}

	public Sort(String column,String direction){
		this.column = column;
		this.direction = Direction.valueOf(direction);
	}

	public static Sort getSort(String column,Direction direction){
		return new Sort(column,direction);
	}

	public static Sort getSort(String column,String direction){
		return new Sort(column,direction);
	}

	public static Sort getSort(String column){
		return new Sort(column, Direction.ASC);
	}

	@Override
	public String toString() {
		return new StringBuilder(" order by ")
				.append(column).append(" ").append(direction.toString()).toString();
	}

	public static void main(String[] args){
		System.out.println(new Sort("test","DESC"));
		System.out.println(new Sort("test", Direction.ASC));
		System.out.println(new Sort("test", Direction.DESC));
	}
}
